<template>
  <div class="container">
    <div class="app-container">
      <el-button class="btn-add" size="mini" type="primary" @click="onPermissions">添加权限</el-button>

      <el-table default-expand-all :data="list" row-key="id">
        <el-table-column prop="name" label="名称" />
        <el-table-column prop="code" label="标识" />
        <el-table-column prop="description" label="描述" />
        <el-table-column label="操作">
          <template v-slot="{ row }">
            <el-button v-if="row.type === 1" size="mini" type="text" @click="onPermissions">添加</el-button>

            <el-button size="mini" type="text" @click="onPermissions">编辑</el-button>

            <el-button size="mini" type="text">删除</el-button>

          </template>

        </el-table-column>

      </el-table>

    </div>
    <accessLayer :show-dialog.sync="showDialog" />
  </div>

</template>

<script>
import accessLayer from './components/accessLayer.vue'
import { getPermissionList } from '@/api/permission'
import { translateListToTreeData } from '@/utils'
export default {
  name: 'Permission',
  components: {
    accessLayer
  },
  data() {
    return {
      list: [],
      showDialog: false
    }
  },
  created() {
    this.getPermissionList()
  },
  methods: {
    // 获取权限列表
    async getPermissionList() {
      this.list = translateListToTreeData(await getPermissionList(), 0) // 将列表数据转化成树形结构
      console.log(this.list)
    },
    // 打开新增弹层
    onPermissions() {
      this.showDialog = true
    }
  }
}
</script>

<style>
.btn-add {
  margin: 10px;
}
</style>
